namespace AltNetUK.Models
{
    using System;
    using System.Web;
    using System.Xml.Serialization;
    using SimpleWebServices;
    using SimpleWebServices.Configuration;
    using SimpleWebServices.Web;

    [XmlRoot(ElementName = "home")]
    public sealed class Home : Resource
    {
        private Credits _credits;
        private ScheduleCollection _schedule;

        [XmlIgnore]
        public Credits Credits
        {
            get
            {
                if (null == this._credits)
                {
                    this._credits = new Default().Object<Credits>();
                }

                return this._credits;
            }
        }

        [XmlIgnore]
        public ScheduleCollection Schedule
        {
            get
            {
                if (null == this._schedule)
                {
                    this._schedule = new Default().Object<ScheduleCollection>();
                }

                return this._schedule;
            }
        }

        [XmlElement(ElementName = "news")]
        public string News
        {
            get;
            set;
        }

        public static Home New(Uri baseUri)
        {
            if (null == baseUri)
            {
                throw new ArgumentNullException("baseUri");
            }

            Home result = new Default().Object<Home>();
            result.CacheControl = HttpCacheability.Public;
            result.Bookmark = baseUri.ToUri(new Uri("2009", UriKind.Relative));
            result.Canonical = baseUri.ToUri(new Uri("2009.en.html", UriKind.Relative));

            return result;
        }
    }
}